import Vue from 'vue'
import App from './App'
import api from './api'
import util from './common/util'
import store from './store'
import Request from '@/js_sdk/luch-request/luch-request/index.js' // 下载的插件
const http = new Request();

http.setConfig((config) => { /* config 为默认全局配置*/
    config.baseURL = ''; /* 根域名 */
    return config
})

// 请求后
http.interceptors.response.use((response) => {
  return response
}, (response) => { /*  对响应错误做点什么 （statusCode !== 200）*/
  //未登录时清空缓存跳转
  if(response.statusCode == 401){
	 uni.removeStorageSync('token')
	 http.setConfig((config) => { /* config 为默认全局配置*/
	     config.header = {
	         Authorization: 'Bearer ', // 演示用
	     }
	     return config
	 })
	 if(response.config.url != '/user'){
		uni.switchTab({
		    url: '/pages/mine/mine'
		});
	 }
  }
  return Promise.reject(response)
})

Vue.config.productionTip = false

App.mpType = 'app'

Vue.prototype.$store = store
Vue.prototype.$api = api
Vue.prototype.$util = util
Vue.prototype.$http = http
Vue.prototype.$baseUrl = ''

const app = new Vue({
	store,
    ...App
})
app.$mount()
